package com.ymatou.iapi.godmch.testcase;

import net.sf.json.JSONObject;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.common.collect.Lists;
import com.ymatou.iapi.godmch.parameter.getBizConfigBean;
import com.ymatou.iapi.godmch.parameter.setBizConfigBean;
import com.ymatou.iapi.godmch.service.getBizConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godmch.biz_config;
import com.ymttest.database.model.godmch.biz_configExample;
import com.ymttest.database.sqlwapper.godmch.biz_configWapper;
/**
*根据bizKey获取业务配置参数
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getBizConfig{
	private static getBizConfigBean bean;
	private static getBizConfigCall call;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据bizKey获取业务配置参数");
	}

	@Before
	public void caseUp() {
		bean=new getBizConfigBean();
		call=new getBizConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_setBizConfig_001() {
		Logger.start(true,"根据bizKey获取业务配置参数");
		try {
			setBizConfigBean setBizConfigBean=GodmchManageCallService.initSetBizConfig();
			GodmchManageCallService.setBizConfig(setBizConfigBean);
			
			biz_configExample example=new biz_configExample();
			biz_configWapper bizWapper=new biz_configWapper();
			example.createCriteria().andBiz_idEqualTo(setBizConfigBean.getBizId());
			biz_config model= bizWapper.selectByExample(example).get(0);
			
			bean.setBizId(setBizConfigBean.getBizId());
			bean.setKeys(Lists.newArrayList(model.getBiz_key()));
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			
			example.createCriteria().andBiz_idEqualTo(setBizConfigBean.getBizId()).andBiz_keyEqualTo(bean.getKeys().get(0));
			model= bizWapper.selectByExample(example).get(0);
			org.json.JSONObject object=new org.json.JSONObject(call.getResult1());
			Logger.verifyEquals(object.get("bizId"), model.getBiz_id(), "验证biz_id");
			Logger.verifyEquals(object.get("bizConfigMap").toString(), "{\""+model.getBiz_key()+"\":\""+model.getBiz_value()+"\"}", "验证bizConfigMap");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}